/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

//#include "Yi_GL.h"
#include "core/网格辅助计算.h"
#include "core/属性.h"
#include "core/shader_binding_ID.h"
#include "core/引擎配置.h"

#include "底层绘图/底层绘图框架.h"
#include "场景/场景.h"
#include "物体/物体.h"
#include "窗口/窗口.h"
#include "纹理/纹理.h"
#include "材质/资产.h"
#include "材质/预设材质.h"
#include "材质/S_Material.h"
#include "系统/多线程.h"
#include "UI/UI.h"

#include "面/面.h"
#include "数学/数学.h"

#include <atomic>


struct S_Engine {
	S_绘图框架*		m_绘图框架;
	static S_UI创建环境*   m_UIctx;
	static bool            m_资源加载线程;
	static bool            g_渲染线程;
	static std::atomic_int g_在运行线程;

	static std::map<uint64, S_Window*> g_窗口容器;

	static std::string     g_着色器文件路径;


	E_绘图API		m_API_Name;

	S_Scene*		m_当前更新场景;

	//static S_板载缓存*     m_预设几何索引;

	S_Engine();
	~S_Engine();


	void f_InitDX12();
	void f_InitVK();

	
	S_设备			f_get设备(uint32 物理设备ID);
	S_设备环境		f_get环境(uint32 物理设备ID, uint32 逻辑设备ID);

	S_设备			f_get光追设备();
	S_设备环境		f_get光追设备环境(uint32 逻辑设备ID);

	S_协处理设备	f_创建绘图设备(uint32 物理设备ID);
	


	void f_Loop();
	void f_asynLoop();
	void f_Close();


	void f_异步创建着色(std::vector<std::string>& name, int32 pyDev=0, int32 logDev=0);

	void f_初始化设备数据(S_设备环境& ctx, bool 启用光追);
	static void f_释放线程数据();
	static void f_释放设备数据();

	static S_Mesh* f_get预设图形网格();

private:
	//S_Window*	m_Window;

	std::vector<void*>	m_绘图设备配置;
};




S_帧渲染层* f_create帧渲染层(C_Widget管理& gm, S_Scene* scene);








template<typename T>
void f_from模型三角网格(S_物体* obj, const T& fun) {
	auto* mesh = f_ob_fromMesh(obj);
	if (mesh) {
		/*S_三角Mesh t;
		
		auto ve = mesh->f_map顶点();
		auto ie = mesh->f_map索引();

		t.m_vert = (vec3*)ve.point;
		t.m_vNum = ve.count;

		t.m_index = (uvec3*)ie.point;
		t.m_iNum = ie.count / 3;

		fun(t);*/
	}
}


